import {fabric} from  "@/js/fabric";
let ShLine = fabric.Line;
let ShPolyline = fabric.Polyline;
(function(){ 
    ShLine.prototype.initialize =function(points, options){
        if (!points) {
            points = [0, 0, 0, 0];
          }
    
          this.callSuper('initialize', options);
    
          this.set('x1', points[0]);
          this.set('y1', points[1]);
          this.set('x2', points[2]);
          this.set('y2', points[3]);
    
          this._setWidthHeight(options);
          wiresClear.call(this)
  };
  })(ShLine);
  (function(){
    ShPolyline.prototype.initialize =function(points, options){
      options = options || {};
      this.points = points || [];
      this.callSuper('initialize', options);
      var calcDim = this._calcDimensions();
      if (typeof options.left === 'undefined') {
        this.left = calcDim.left;
      }
      if (typeof options.top === 'undefined') {
        this.top = calcDim.top;
      }
      this.width = calcDim.width;
      this.height = calcDim.height;
      this.pathOffset = {
        x: calcDim.left + this.width / 2,
        y: calcDim.top + this.height / 2
      };
      wiresClear.call(this)
  };
  })(ShPolyline);
  function wiresClear(){
    let that = this;
    that.on("removed", function() {
      that.target && clearWires(that.target, that);
      that.source && clearWires(that.source, that);
    });
}
function clearWires(target, wires) {
  for (let item in target.hotpotslist) {
    target.hotpotslist[item] = target.hotpotslist[item].filter(
      element => {
        return wires !== element;
      }
    );
  }
}
  export {ShLine,ShPolyline};